package com.example.vue20220402.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.vue20220402.pojo.Patient;
import com.example.vue20220402.dao.PatientMapper;
import com.example.vue20220402.pojo.Role;
import com.example.vue20220402.service.IPatientService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.vue20220402.vo.Constant;
import com.example.vue20220402.vo.ResultData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author rock
 * @since 2022-04-14
 */
@Service
public class PatientServiceImpl  implements IPatientService {

    @Resource
    PatientMapper patientMapper;
    @Override
    public ResultData getPatient(Patient patient) {
        ResultData rd = new ResultData();
        QueryWrapper<Patient> qw = new QueryWrapper();
        if(patient.getUserId() != null ){
            qw.eq("user_id",patient.getUserId());
        }
        List<Patient> list = patientMapper.selectList(qw);
        if(list == null || list.size() < 1){
            //  如果没有数据的话   提示用户添加数据  先自动生成一条默认数据
            patient.setPatientName("系统示例");
            patient.setPatientAge(1);
            patient.setPatientSex(1);
            patient.setPatientTel("13111111111");
            patientMapper.insert(patient);
            list.add(patient);
        }
        rd.setResult(list);
        return rd;
    }

    @Override
    public ResultData editpat(Patient patient) {
        ResultData rd = new ResultData();
        patientMapper.updateById(patient);
        rd.setCode(Constant.OK.getCode());
        return rd;
    }
}
